#include "verilated.h"
#include "verilated_vcd_c.h"
#include "Vtop.h"

VerilatedContext* contextp = NULL;
VerilatedVcdC* tfp = NULL;

static Vtop* top;

void step_and_dump_wave() {
	top->eval();
	contextp->timeInc(1);
	tfp->dump(contextp->time());
}

void sim_init() {
	contextp = new VerilatedContext;
	tfp = new VerilatedVcdC;
	top = new Vtop;
	contextp->traceEverOn(true);
	top->trace(tfp, 0);
	tfp->open("dump.vcd");
}

void sim_exit() {
	step_and_dump_wave();
	tfp->close();
	top->final();
}

int main() {
	sim_init();

	for(int i = 0; i <= 20; i++) {
		if(i == 0) {
			top->reset = 1;
			top->in = 2;
			step_and_dump_wave();

			top->reset = 0;
			step_and_dump_wave();
		}
		top->clock = 0;
		step_and_dump_wave();
		top->clock = 1;
		step_and_dump_wave();
	}
	
	sim_exit();
}
